#!/usr/bin/env python
# encoding: utf-8
# @author: liusir
# @file: config_utils.py
# @time: 2022/11/2 8:43 PM

import configparser
import os
import time

current_path = os.path.dirname(os.path.abspath(__file__))
config_file_path = os.path.join(current_path,'..','conf','local_config.ini')

class ConfigUtils():
    def __init__(self,cfg_path=config_file_path):
        self.cfg = configparser.ConfigParser()
        self.cfg.read( cfg_path )
    @property   # 让方法变为属性方法
    def HOSTS(self):
        hosts_value = self.cfg.get('default','hosts')
        return hosts_value
    @property
    def REPORT_PATH(self):
        report_path_value = self.cfg.get('path','report_path')
        return report_path_value
    @property
    def LOG_FILE_PATH(self):
        log_file_path = '%s_%s.log'%(self.cfg.get('default','log_name'),
                                             time.strftime('%Y_%m_%d'))
        return log_file_path
    @property
    def MYSQL_SERVER_IP(self):
        mysql_server_ip_value = self.cfg.get('mysql','mysql_server_ip')
        return mysql_server_ip_value
    @property
    def MYSQL_USER(self):
        mysql_user_value = self.cfg.get('mysql','mysql_user')
        return mysql_user_value
    @property
    def MYSQL_PASSWORD(self):
        mysql_mysql_password_value = self.cfg.get('mysql','mysql_password')
        return mysql_mysql_password_value
    @property
    def SMTP_SERVER(self):
        smtp_server_value = self.cfg.get('email','smtp_server')
        return smtp_server_value
    @property
    def SMTP_SENDER(self):
        smtp_sender_value = self.cfg.get('email','smtp_sender')
        return smtp_sender_value
    @property
    def SMTP_PASSWORD(self):
        smtp_password_value = self.cfg.get('email','smtp_password')
        return smtp_password_value
    @property
    def SMTP_RECEIVER(self):
        smtp_receiver_value = self.cfg.get('email','smtp_receiver')
        return smtp_receiver_value
    @property
    def SMTP_CC(self):
        smtp_cc_value = self.cfg.get('email','smtp_cc')
        return smtp_cc_value

    @property
    def SMTP_SUBJECT(self):
        smtp_subject_value = self.cfg.get('email', 'smtp_subject')
        return smtp_subject_value

local_config = ConfigUtils()

if  __name__=="__main__":
    print( local_config.HOSTS )
    print( local_config.REPORT_PATH )
    print( local_config.LOG_FILE_PATH )